;;; $Id: main.sld 348 2013-12-03 20:24:17Z alan.watson.f $

(define-library (oaxaca main)

  (export main
          startup)

  (import (scheme base)
          (scheme process-context))

  (import (oaxaca file)
          (oaxaca log)
          (oaxaca load)
          (oaxaca repl))

  (begin

    (make-directory (oaxaca-directory-path))

    (define (startup)
      (let ((startup-file-path (make-path (oaxaca-directory-path) "etc" "oaxaca.scm")))
        (when (file-exists? startup-file-path)
          (log-info "")
          (log-info "loading startup file.")
          (log-info "")
          (guard (object
                  ((error-object? object)
                   (log-error object))
                  (else
                   (log-error "unhandled exception during startup.")))
            (load startup-file-path))
          (log-info "finished loading startup file.")
          (log-info ""))))

    (define (main)
      (log-info "starting repl.")
      ;;(startup)
      (repl)
      (log-info "exiting repl.")
      (exit 0))))
